package com.example.server.controller.admin;

import com.example.server.common.config.annotation.MustLogin;
import com.example.server.common.config.auth.TokenUser;
import com.example.server.common.constant.Result;
import com.example.server.service.admin.VersionService;
import com.example.server.vo.ButtonVO;
import com.example.server.vo.VersionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * @author china.fuyao@outlook.com
 * @date 2020-04-20 18:36
 */
@Api(tags = "Admin版本相关接口")
@RestController
@RequestMapping("/admin/version")
public class AdminVersionController {
    @Resource
    VersionService versionService;

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "版本列表", notes = "版本列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "page", required = true),
            @ApiImplicitParam(value = "数量", name = "limit", required = true),
            @ApiImplicitParam(value = "客户端类型", name = "clientType", required = false),
            @ApiImplicitParam(value = "系统类型", name = "clientSys", required = false)
    })
    @GetMapping("/list")
    public Result versionList(Integer page, Integer limit, Integer clientType, Integer clientSys, @ApiIgnore TokenUser tokenUser) {
        return versionService.versionList(page, limit, clientType, clientSys, tokenUser.getCustomerId());
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "添加版本", notes = "添加版本")
    @PostMapping("/add")
    public Result addVersion(@RequestBody VersionVO versionVO, @ApiIgnore TokenUser tokenUser) {
        return versionService.addVersion(versionVO, tokenUser.getCustomerId());
    }


    @MustLogin(isAdmin = true)
    @ApiOperation(value = "更新版本", notes = "更新版本")
    @PostMapping("/update")
    public Result updateVersion(@RequestBody VersionVO versionVO, @ApiIgnore TokenUser tokenUser) {
        return versionService.updateVersion(versionVO, tokenUser.getCustomerId());
    }


    @MustLogin(isAdmin = true)
    @ApiOperation(value = "删除版本", notes = "删除版本")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "versionIds", required = true)
    })
    @PostMapping("/delete")
    public Result deleteVersion(String versionIds, @ApiIgnore TokenUser tokenUser) {
        return versionService.deleteVersion(versionIds, tokenUser.getCustomerId());
    }
}